#!/bin/bash
set -ex
:<<EOF
if [ -f /etc/debian_version ]; then
  sudo apt-get update
  sudo apt-get install -y git python-pip python-dev
elif [ -f /etc/redhat-release ]; then
#  rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
  yum install -y epel-release
  yum install -y git python-pip python-devel python-dnf
fi
sudo pip install ansible
EOF

sudo apt update
sudo apt install -y software-properties-common
#然后键入以下命令添加Ansible PPA：
sudo apt-add-repository -y ppa:ansible/ansible
sudo apt update
sudo apt install -y ansible

#sudo mkdir -p /etc/ansible/roles
#sudo ln -s /vagrant /etc/ansible/roles/ansible-zfs
:<<EOF
# -c 忽略证书SSL安全
# /home/vagrant/.ansible/roles 下安装了2个role ansible-network-tweaks  ansible-zfs
sudo ansible-galaxy install -r /vagrant/zfs/requirements.yml -f -c
sudo ansible-galaxy install -r /vagrant/zfs/requirements.yml -c
EOF
#或者手工设置
mkdir /home/vagrant/.ansible/roles -p
pushd /vagrant/zfs/
 cp -rf ansible-network-tweaks  ansible-zfs /home/vagrant/.ansible/roles/
popd

sudo ansible-playbook -i "localhost," -c local /vagrant/zfs/playbook.yml
